package com.hcxdi.calanderapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Toast;

import com.hcxdi.calanderapp.bean.DayBean;
import com.hcxdi.calanderapp.widget.CalendarView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    CalendarView calendarView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        calendarView=findViewById(R.id.calendarView);
        List<DayBean> list=new ArrayList<>();
        list.add(getData("2021-05-23 14:58:46"));
        list.add(getData("2021-05-24 14:58:46"));
        list.add(getData("2021-05-25 14:58:46"));
        list.add(getData("2021-05-26 14:58:46"));

        list.add(getData("2021-06-03 14:58:46"));
        list.add(getData("2021-06-04 14:58:46"));
        calendarView.setChoose(list);
        calendarView.setOnChooseListener(new CalendarView.OnChooseListener() {
            @Override
            public void onChoose(DayBean startDate, DayBean endDate) {
                Toast.makeText(MainActivity.this,new SimpleDateFormat("yyyy-MM-dd").format(startDate.getDate())+"~"+new SimpleDateFormat("yyyy-MM-dd").format(endDate.getDate()),Toast.LENGTH_SHORT).show();
            }
        });
    }

    private DayBean getData(String time){
        DayBean dateBean = new DayBean();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date parse = sdf.parse(time);
            dateBean.setDate(parse);

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dateBean;
    }
}